package com.hzw.saas.service.product.service;


import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzw.saas.api.product.IProductPaperService;
import com.hzw.saas.api.product.bo.ProductLiteratureBO;
import com.hzw.saas.common.util.MapperUtil;
import com.hzw.saas.service.product.mapper.ProductPaperMapper;


import com.hzw.saas.service.product.model.ProductPaper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;


@RequiredArgsConstructor
@Service("productLiteratureService")
public class ProductPaperServiceImpl extends ServiceImpl<ProductPaperMapper, ProductPaper> implements IProductPaperService, IService<ProductPaper> {


    @Override
    public List<ProductLiteratureBO> findByProductId(String productId) {
        List<ProductPaper> list = this.lambdaQuery().eq(ProductPaper::getProductId, productId)
            .orderByDesc(ProductPaper::getPubYear)
            .list();
        if (CollectionUtil.isNotEmpty(list)){
            return MapperUtil.nt().mapAsList(list,ProductLiteratureBO.class);
        }
        return Collections.emptyList();
    }
}
